package com.zsxb.crm.controller;

import com.zsxb.crm.annotation.Log;
import com.zsxb.crm.dto.ContractDTO;

import com.zsxb.crm.dto.ContractSaveDTO;
import com.zsxb.crm.pojo.Contract;
import com.zsxb.crm.result.PageResult;
import com.zsxb.crm.result.Result;
import com.zsxb.crm.service.ContractService;
import com.zsxb.crm.vo.ContractVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//合同
@RestController
@RequestMapping("/contract")
@Slf4j
public class ContractController {
    @Autowired
    private ContractService contractService;

    @GetMapping("/list")
    private PageResult list(ContractDTO dto){
         log.info("查询合同接收到的参数为{}",dto);
        PageResult result=   contractService.list(dto);
        return PageResult.success(result);
    }
    //修改合同
    @Log
    @PutMapping
    public Result update(@RequestBody ContractDTO dto){
        log.info("修改合同接收到的参数为{}",dto);
        contractService.update(dto);
        return Result.success();
    }
    //根据id查询合同
    @GetMapping("/detail/{id}")
    public Result getById(@PathVariable Long id){
        log.info("根据id查询合同：{}",id);
        Contract  contract = contractService.getById(id);
        return Result.success(contract);
    }
    //根据id查询合同
    @GetMapping("/{id}")
    public Result getById2(@PathVariable Long id){
        log.info("根据id查询合同：{}",id);
        ContractVO contract = contractService.getById2(id);
        return Result.success(contract);
    }

    /**
     *     新增合同
      */
    @Log
    @PostMapping
    public Result<String> addContract(@RequestBody ContractSaveDTO contractSaveDTO){
        contractService.addContract(contractSaveDTO);
        return Result.success();
    }



}
